package com.event.example.jpa;

import cn.hutool.core.util.RandomUtil;
import com.event.example.jpa.service.SmsJapService;
import com.event.example.jpa.service.TagJapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("jpa")
public class JpaController {

    @Autowired
    private TagJapService tagService;

    @Autowired
    private SmsJapService smsService;

    @GetMapping("update")
    public Object update(Integer id,String tagName) {
        TagEntity tag = new TagEntity();
        tag.setTagId(id);
        tag.setTagName(tagName);
        tag.setAppId(0);
        tagService.update(tag);
        return tag;
    }

    @GetMapping("add")
    public Object add(String tagName) {
        TagEntity tag = new TagEntity();
        tag.setTagName(tagName);
        tag.setAppId(0);
        tagService.save(tag);
        return tag;
    }

    @GetMapping("del")
    public Object del(Integer id) {
        tagService.del(id);
        return id;
    }

    @GetMapping("get")
    public Object get(Integer id) {
        return tagService.get(id);
    }
}
